# f = open('name.txt', encoding ='UTF-8')
# data = f.read()
# print(data.split('|'))
#
# f2 = open('weapon.txt', encoding ='UTF-8')
# data2 = f2.read()
# i = 1
# for line in f2.readlines():
#     if i%2==1:
#         print(line.strip('\n')) # 删除换行符号
#     i += 1
#
# f3 =open('sanguo.txt', encoding='GB18030')
# print(f3.read().replace('\n', ' '))

'''
re.findall(), f.read().replace('\n', ''), line.split
'''
import re


def find_item(hero):
    with open('sanguo.txt', encoding='GB18030') as f:
        data = f.read().replace('\n', '')
        name_num = re.findall(hero, data)
        #print('主角  %s    出现 %s 次' % (hero, len(name_num)))
    return len(name_num)


name_dict = {}
with open('name.txt', encoding='utf-8') as f:
    for line in f:
        names = line.split('|')
        print(names)
        for n in names:
            all = find_item(n)
            name_dict[n] = all
print(name_dict)
